<template>
  <div>
    <myheaders></myheaders>
    <br /><br />
    <!-- 面包屑导航 -->
    <Breadcrumb :datas="datas"></Breadcrumb>
    <br /><br />
    <div>
      <center>
        请输入密码：<input type="password" v-model="Opass" /><br /><br />
        请输入新密码：<input type="password" v-model="Npass1" /><br /><br />
        请确认密码：<input type="password" v-model="Npass2" /><br /><br />
        <Button color="green" @click="submit">提交修改</Button>
      </center>
    </div>
    <myfooters></myfooters>
  </div>
</template>

<script>
// 导入头部组件及尾部组件
import myheader from "./myheader";
import myfooter from "./myfooter";

export default {
  data: function() {
    return {
      datas: [
        { title: "首页", route: { name: "index" } },
        { title: "修改密码" }
      ],
      Opass: "",
      Npass1: "",
      Npass2: ""
    };
  },
  components: {
    myheaders: myheader,
    myfooters: myfooter
  },
  methods: {
    submit() {
      if (this.Opass) {
        if (this.Npass1) {
          if (this.Npass2) {
            if (this.Npass1 == this.Npass2) {
              this.axios({
                url: "http://localhost:8000/update_pass/",
                params: {
                  Opass: this.Opass,
                  Npass: this.Npass2,
                  uid: localStorage.getItem("uid")
                }
              }).then(res => {
                console.log(res);
                this.$Message(res.data.msg);
                if (res.data.code == 200) {
                  localStorage.removeItem("username");
                  this.$router.push("/login");
                }
              });
            } else {
              this.$Message("两次密码输入不一致");
            }
          } else {
            this.$Message("请确认密码");
          }
        } else {
          this.$Message("请输入新密码");
        }
      } else {
        this.$Message("请输入密码");
      }
    }
  }
};
</script>

<style>
</style>